package my.suveng.oauth2.model.struct;

import my.suveng.oauth2.model.dto.PermissionAddDto;
import my.suveng.oauth2.model.dto.PermissionEditDto;
import my.suveng.oauth2.service.db.mysql.model.entity.SysPermission;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface SysPermissionStructMapper {

    SysPermissionStructMapper INSTANCE = Mappers.getMapper(SysPermissionStructMapper.class);

    /**
     * dto -> entity
     * 
     * @author suwenguang
     */
    @Mappings({ @Mapping(target = "name", source = "dto.permissionName"),
            @Mapping(target = "createTime", ignore = true), @Mapping(target = "creator", ignore = true),
            @Mapping(target = "id", ignore = true), @Mapping(target = "modifyTime", ignore = true),
            @Mapping(target = "status", ignore = true), @Mapping(target = "updator", ignore = true) })
    SysPermission dto2entity(PermissionAddDto dto);

    List<SysPermission> dtos2entitys(List<PermissionAddDto> dtos);

    /**
     * dto -> entity
     * 
     * @author suwenguang
     */
    @Mappings({ @Mapping(target = "id", source = "id"), @Mapping(target = "name", source = "name"),
            @Mapping(target = "createTime", ignore = true), @Mapping(target = "creator", ignore = true),
            @Mapping(target = "modifyTime", ignore = true), @Mapping(target = "status", ignore = true),
            @Mapping(target = "updator", ignore = true) })
    SysPermission dto2entity(PermissionEditDto dto);

    List<SysPermission> editDto2entitys(List<PermissionEditDto> dtos);

}
